package reflection;

/**
 * 测试Class类的创建方式有哪些
 */
public class Test03 {
    public static void main(String[] args) throws ClassNotFoundException {
        Person person = new Student();
        System.out.println(person.name);
        //通过对象获得Class类
        Class c1 = person.getClass();
        System.out.println(c1.hashCode());
        //forname获得
        Class c2 = Class.forName("reflection.Student");
        System.out.println(c2.hashCode());
        //使用类名
        Class<Student> studentClass = Student.class;
        System.out.println(studentClass.hashCode());
        //通过type类型获取
        Class<Integer> type = Integer.TYPE;
        System.out.println(type);
        //获取父类类型
        Class superclass = c1.getSuperclass();
        System.out.println(superclass);
    }

}

class Person {
    public String name;

    public Person() {
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                '}';
    }
}

class Student extends Person {
    public int age;
    public Student() {
        this.name = "学生";
    }
}

class Teacher extends Person {
    public Teacher() {
        this.name = "老师";
    }
}
